<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../../assets/libs/jquery/jquery-3.6.1.min.js"></script>
</head>

<body>
  <ul>
    <li>Hello world!</li>
    <li>Hello world! 2</li>
    <li>Hello world! 3</li>
    <li>Hello world! 4</li>
    <li>Hello world! 5</li>
    <li>Hello world! 6</li>
  </ul>

  <script>
    // 事件委托
    $('ul').on('click', 'li', event => {
      $('li').css('color', 'black')
      $(event.target).css('color', '#17f')
    })

    // 动态添加的元素，不需要特殊处理
    $('ul').append($('<li>Hello world! 7</li>'))

    // 注销事件监听
    $('ul').off('click', 'li')
  </script>
</body>

</html>